<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>组件</title>
    <script src="./js/react.development.js"></script>
    <script src="./js/react-dom.development.js"></script>
    <script src="./js/babel.min.js"></script>
    <style>
      header {
        height: 100px;
        background: #aef;
      }
      main {
        height: 400px;
        background: rgb(162, 140, 184);
      }
      footer {
        height: 100px;
        background: rgb(212, 161, 126);
      }
    </style>
  </head>
  <body>
    <div id="root"></div>
    <script type="text/babel">
      //声明一个类
      class Top extends React.Component {
        //render 方法的名字是固定的
        render(){
          //返回虚拟 DOM 对象
          return <header></header>;
        }
      }

      //内容组件
      class Content extends React.Component{
        render(){
          return <main></main>;
        }
      }

      //底部内容组件
      class Bottom extends React.Component{
        render(){
          return <footer></footer>;
        }
      }

      // <Top></Top> 组件标签. 渲染过程中, 会根据标签名找同名的类, 实例化对象, 实例化对象调用 render 方法得到虚拟 DOM 对象
      class App extends React.Component{
        render(){
          return <div>
            <Top></Top>
            <Content />
            <Bottom />
          </div>
        }
      }      

      //渲染
      ReactDOM.render(<App />, document.querySelector("#root"));
    </script>
  </body>
</html>
